<!DOCTYPE html>
<html class="ui-page-login">

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>忘记密码</title>
	<link rel="stylesheet" href="css/CFNetPP_Base.css">
	<link href="css/mui.min.css" rel="stylesheet" />
	<link href="css/style.css" rel="stylesheet" />
	<link rel="stylesheet" href="css/base.css">
</head>
<body style="height: auto;">
	  <div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
<div class="base_navigation_bar base_style_color base_navigation_item_bar">
	<a class="base_left_item" href="#" onclick="backClick()">
		<img class="base_back_icon" src="image/icon_jiantou.png" alt="">
	</a>
	<span>忘记密码</span>
	<a class="base_right_item base_hide_item">
	</a>
</div>
<div class="forgetpassword" >
	<div class="mui-content">
		<form class="mui-input-group base_dark_grey">
			<div class="mui-input-row div-phone">
				<label class="base_dark_grey" for="phone">手机号：</label>
				<input id='phone' type="tel" maxlength="11" class="base_content_font mui-input-clear mui-input" placeholder="请输入手机号码" onkeyup="this.value=this.value.replace(/\D/g,'')" >
			</div>             	
			<div class="mui-input-row code">
				<label class="base_dark_grey">验证码：</label>
				<input id='editcode' type="tel" maxlength="6" class="mui-input surecode base_content_font" placeholder="请输入验证码" onkeyup="this.value=this.value.replace(/\D/g,'')">
				<button type="button" id="sendcode" class="sendcode base_content_font mui-btn-red" onclick="sends.send();">发送验证码</button>
			</div>
			<div class="mui-input-row">
				<label class="base_dark_grey">新密码：</label>
				<input id='password' type="password" class="mui-input base_content_font" placeholder="请输入新密码" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
				<img src="image/icon_see0.png" alt=""  class="showpassword" id="showpassword">
			</div>
		</form>
		<div class="mui-content-padded">
			<button id='' class="mui-btn-block mui-btn-submit" onclick="revisePWDClick()">重置密码</button>
		</div>
	</div>
</div>
<script type="text/javascript" src="script/jquery.min.js"></script>
<script type="text/javascript" src="script/mui.min.js"></script>
<script type="text/javascript" src="script/MD5.js"></script>
<script type="text/javascript" src="script/requestTool.js"></script>
<script>
var currentPhoneNumber = '';//当前获取验证码手机号
var currentCode = '';//当前验证码
var sends = {
	checked:1,
	send:function(){
//		var pattern = /(13\d|14[57]|15[^4,\D]|17[678]|18\d)\d{8}|170[059]\d{7}/,
		str = '';
		// 手机号正则验证
//		var phoneNum=pattern.test($("#phone").val());
          var phoneNum= $("#phone").val();
		if(phoneNum.length==11){
			var time = 60;
			timeCountDown();
			var timer = setInterval(timeCountDown,1000);//倒计时
			$("#sendcode").attr("disabled","disabled")
			currentPhoneNumber = $("#phone").val();
			sendCode();
		}else{
			api.toast({
			    msg: '请输入正确的手机号码'
			});
		}
		function timeCountDown(){
			if(time==0){
				clearInterval(timer);
				$('#sendcode').html("再次发送验证码");
				$("#sendcode").removeAttr("disabled")//禁止点击
				sends.checked = 1;
				return true;
			}
			$('#sendcode').html(time+"S后再次发送");
			time--;//倒计时
			return false;
			sends.checked = 0;
		}
	}
}
function sendCode(){//发送验证码
	currentCode = getCode();
	var timecode = Date.parse(new Date);
	var token = MD5("cfnetsms" + timecode);
	var url = 'http://boscache.cfnet.org.cn/sms/smsauth.php' + '?timecode=' + timecode + '&token=' + token + '&tel=' + currentPhoneNumber + '&authcode=' + currentCode;
	api.ajax({
		tag : 'code',
		url : url
	}, function(ret, err) {
		// alert('ret:'+JSON.stringify(ret)+'err:'+JSON.stringify(err));
		api.cancelAjax({
			tag : 'code'
		});
	});
}
function getCode(){//获取验证码
	return getRandom(8999) + 1000;
}
$(function(){
	$("#showpassword").click(function(){
		//切换密码是否可见
		if($("#password").attr("type")=="password"){
			$("#password").attr("type","text");
			$('#showpassword').attr('src','image/icon_see1.png');
		}else{
			$("#password").attr("type","password");
			$('#showpassword').attr('src','image/icon_see0.png');
		}
	})
})
apiready = function(){
    
}
function backClick(){
	api.closeWin();
}
//转换时间戳  2010-12-23 10:53
function getLocalTime(tm) {

	var d = new Date(tm * 1000);
	var date = (d.getFullYear()) + "-" + (d.getMonth() + 1) + "-" + (d.getDate()) + " " + (d.getHours()) + ":" + (d.getMinutes()) + ":" + (d.getSeconds());
	return date;

}

//产生随机数
function getRandom(n) {
	return Math.floor(Math.random() * n + 1)
}
//修改密码
function revisePWDClick(){
	var editcode = $('#editcode').val();
	var editTel = $('#phone').val();
	if (editcode == '' || editTel == '') {
		api.toast({
		    msg: '手机号或验证码不能为空！'
		});
		return;
	}
	if (editcode != currentCode || editTel != currentPhoneNumber) {
		api.toast({
		    msg: '验证码错误！'
		});
		return;
	}
	var password = $('#password').val();
	if (password == '') {
		api.toast({
		    msg: '请输入要修改的密码！'
		});
		return;
	}
	var params = {
		phonenumber : editTel,
		password : password
	};
	cfnetppPOST(urlUpdatepwd,
		params,
		false,
		function(data, status){
//				alert('ret:'+JSON.stringify(data));
			if (status == 'success') {
				if (data.status == 1) {
					api.toast({
					    msg: '修改密码成功！'
					});
					api.sendEvent({
					    name: 'changepwdNotifi'
					});
					setTimeout(function(){
						api.closeWin();
					}, 1000);
				}else{
					if (data.status == 3) {
						api.toast({
						    msg: '新密码不能与旧密码相同！'
						});
					}else{
						api.toast({
						    msg: '修改密码失败！'
						});
					}
				}
			}else{
				api.toast({
				    msg: '修改密码失败！'
				});
			}
		});
}
</script>
</body>

</html>